package com.miluGame.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.miluGame.entity.Role;
import com.miluGame.service.RoleService;
/**
 * 角色
 * @author Administrator
 *
 */
@Controller
@RequestMapping("role")
public class RoleController {
	
	@Autowired
	private RoleService roleService;
	
	/**
	 * 角色列表
	 * @param rq
	 * @param rsp
	 * @return
	 */
	@RequestMapping("/roleManager.go")
	public String roleManager(HttpServletRequest rq,HttpServletResponse rsp){
		int pageNum = Integer.parseInt(rq.getParameter("pageNum")==null?"0":rq.getParameter("pageNum").toString());     
		int pageSize  = Integer.parseInt(rq.getParameter("pageSize")==null?"10":rq.getParameter("pageSize").toString());
		Map paramMap = new HashMap();
		//paramMap.put("", value)
		rq.setAttribute("roleList", roleService.getMenusByRole(pageSize, pageNum));
		rq.setAttribute("count", roleService.countRoles());
		return "WEB-INF/role";
	}
	
	/**
	 * 添加角色
	 * @param role
	 * @return
	 */
	@RequestMapping("/addRole.go")
	public String insertRole(HttpServletRequest req,HttpServletResponse rsp,Role role){
		String roleName = req.getParameter("roleName").toString();
		String roleDis = req.getParameter("roleDis").toString();
		if(roleService.insertRole(roleName, roleDis,rsp)>0){
			return "redirect:../role/roleManager.go";
		}else{
			return "WEB-INF/role";
		}
	}
	
	/**
	 * 修改角色信息
	 * @param role
	 * @return
	 */
	@RequestMapping("editRole.go")
	public String editRole(Role role){
		
		
		return "";
	}
	
	/**
	 * 根据角色标识删除角色信息
	 * @param id
	 * @return
	 */
	@RequestMapping("delRole.go")
	public String delRole(Integer id){
		
		return "";
	}
}
